import {firstUpperCase} from '@/utils/index'
const getBtn = (
  txt,
  funType,
  row,
  h,
  context,
  type = 'primary',
  parent,
  parentIndex
) => {
  return (
    <a
      href="javascript:;"
      class={`text-${type}`}
      onClick={() =>
        context[`on${firstUpperCase(funType)}`](row, parent, parentIndex)
      }
    >
      {txt}
    </a>
  )
}
// 产品类型
export const typeList = [
  {
    name: '兑换券',
    value: '1'
  },
  {
    name: '优惠券',
    value: '2'
  }
]

export const columns = ctx => {
  const checkStatus = ctx.searchForm.checkStatus
  const isDraft = checkStatus !== '3' && checkStatus !== '0'
  return [
    {
      prop: isDraft ? 'relationId' : 'id',
      label: '方案ID'
    },
    {
      prop: 'name',
      label: '特殊节假日方案名称'
    },
    {
      prop: 'exchangeRangeName',
      label: '兑换范围',
      hide: isDraft
    },
    {
      prop: 'productTypeName',
      label: '产品类型',
      hide: isDraft
    },
    {
      prop: 'operator',
      label: '操作人'
    },
    {
      prop: 'updateTime',
      label: '修改时间'
    },
    {
      prop: 'orderNumber',
      label: '关联销售单数量',
      hide: isDraft
    },
    {
      label: '操作',
      width: 200,
      render: (h, row, index) => {
        // let checkStatus = ctx.searchForm.checkStatus
        let btns = []
        let edit = getBtn('修改', 'edit', row, h, ctx)
        let remodify = getBtn('重新修改', 'remodify', row, h, ctx)
        let tjsp = getBtn('提交审批', 'submit', row, h, ctx)
        let backApproval = getBtn('撤销审批', 'backApproval', row, h, ctx)
        let detail = getBtn('详情', 'detail', row, h, ctx)
        // 3:已通过，2：被驳回，1：审批中，4：已撤销，0：未提交
        if (checkStatus === '3') {
          btns = [remodify, detail]
        } else if (['2', '4'].includes(checkStatus)) {
          btns = [tjsp, remodify, detail]
        } else if (checkStatus === '0') {
          btns = [tjsp, edit, detail]
        } else if (checkStatus === '1') {
          btns = [backApproval, detail]
        }
        return btns
      }
    }
  ]
}
